//
//  MicroMedicalViewController.m
//  WE
//
//  Created by 要帅气的生活 on 15/11/18.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "MicroMedicalViewController.h"
#import "RegistrationViewController.h"
#import "Head.h"
#import "OneCell.h"
#import "TwoCell.h"
#import "ThreeCell.h"
#import "FourCell.h"
#import "FiveCell.h"
#import "HeadView.h"
#import "TheinquiryViewController.h"
#import "FocusonViewController.h"
#import "QuickaboutViewController.h"
#import "ThesearchView.h"
#import "HotViewController.h"
#import "TeamViewController.h"
#import "ModelCrowdViewController.h"
#import "InformationForDetailsViewController.h"
#import "Size.h"
#import "MoreTeamViewController.h"
#import "SingletonStoreSimpleData.h"

#import <MJRefresh.h>
@interface MicroMedicalViewController ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>

{
    UIView *searchView ;
}

@property (nonatomic,retain) UISearchBar *searchbar;
//@property (nonatomic,retain) UISearchBar *searchbar;
@property (nonatomic,retain) NSArray *arr;
@property (nonatomic,strong) UITableView *table;
@property (nonatomic,strong) ThesearchView *shai;
@end

@implementation MicroMedicalViewController
- (void)viewDidAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = YES;
    
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
    [SingletonStoreSimpleData shareViewController].array = nil;
}


//- (void)viewWillDisappear:(BOOL)animated{
//    self.navigationController.navigationBar.hidden = NO;
//}
//- (void)viewDidDisappear:(BOOL)animated{
//    self.navigationController.navigationBar.hidden = NO;
//    //[searchView removeFromSuperview];
//}


- (void)viewDidLoad {
    [super viewDidLoad];
    //self.navigationController.navigationBarHidden = NO;
    
//    self.tabBarController.tabBar.hidden = NO;
    //self.tabBarController.tabBar.hidden= NO;
    self.navigationController.navigationBar.hidden = YES;

//    self.tabBarController.tabBar.hidden = NO;
    self.navigationItem.title = @"123";
//    self.navigationController.navigationBar.hidden = YES;
//    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
//    
//    self.navigationItem.titleView = view;
    
    self.arr = @[@"妇产科",@"皮肤科",@"儿科",@"普外科",@"耳鼻喉科",@"骨科",@"内消化科",@"男科"];
    
    [self Table];
    [self searchBarview];
    [self HeadView];
}
-(void)Table{
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-113) style:UITableViewStyleGrouped];
//    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-49) style:UITableViewStyleGrouped];
    [self.view addSubview:_table];
    _table.showsVerticalScrollIndicator = NO;
    _table.delegate = self;
    _table.dataSource = self;
    _table.separatorStyle = NO;
    
}
-(void)HeadView{
    UIView *head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 190*Height)];
    head.backgroundColor = [UIColor whiteColor];
    NSArray *arr = @[Colorone,Colortwo,Colorthree,Colorone];
    NSArray *array = @[Colortwo,Colorthree,Colorone,Colortwo];
    _table.tableHeaderView = head;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            BaseView *base = [[BaseView alloc] initWithFrame:CGRectMake((30*Width+85*j)*Width, (10*Height+90*i)*Height, 60*Width, 80*Height)];
            [head addSubview:base];
            base.tag = 100+j+i*10;
            
            UIView *tupian = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60*Width, 60*Width)];
            [base addSubview:tupian];
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10*Width, 10*Width, 40*Width, 40*Width)];
            img.image = [UIImage imageNamed:[NSString stringWithFormat:@"heda%d%d.png",i,j]];
            [tupian addSubview:img];
            tupian.layer.cornerRadius = 30*Width;
            if (i == 0) {
                tupian.backgroundColor = arr[j];
            }else{
                tupian.backgroundColor = array[j];
            }
            UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 60*Width, 60*Width, 20*Height)];
            name.textAlignment = 1;
            name.text = self.arr[i*4+j];
            name.font = [UIFont boldSystemFontOfSize:12];
            [base addSubview:name];
            [base addTarget:self selector:@selector(Head:)];
        }
    }
}
-(void)Head:(BaseView *)view{
    
    SectionsViewController * secVC = [[SectionsViewController alloc] init];
    if (view.tag <104) {
        
        secVC.titleStr = _arr[view.tag - 100];
        [self.navigationController pushViewController:secVC animated:YES];
    }else{
        secVC.titleStr = _arr[view.tag - 106];
        [self.navigationController pushViewController:secVC animated:YES];
    }
    
//    NSLog(@"%ld",view.tag);
    
}
-(void)searchBarview
{
    ThesearchView *search = [[ThesearchView alloc] initWithFrame:self.shai.frame = CGRectMake(0, 0,  WindowWidth, 64)];
//    search.backgroundColor = DEBUG_CLOLR;
    search.searchbar.placeholder = @"搜索医院，医生，科室，疾病";
    search.searchbar.barTintColor = [UIColor whiteColor];
    [ToolUtil createLine:63 superView:search lift:0 width:WindowWidth hight:1 color:[UIColor grayColor]];
    
//    [ToolUtil createVerticalLine:0 superView:self.view lift:15 height:110];
    
    [self.view addSubview:search];


}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    
}
-(void)saomiao{
    
    NSLog(@"扫描");
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 1;
    }else if (section == 3){
        return 1;
    }else if (section == 4){
        return 4;
    }else{
        return 0;
    }
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 4) {
        NSLog(@"44444");
        InformationForDetailsViewController *details = [[InformationForDetailsViewController alloc] init];
        [self.navigationController pushViewController:details animated:YES];
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        OneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"one"];
        if (cell == nil) {
            cell = [[OneCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"one"];
        }
        [cell.registered addTarget:self selector:@selector(registered)];
        [cell.Theinquiry addTarget:self selector:@selector(Theinquiry)];
        [cell.Quickabout addTarget:self selector:@selector(Quickabout)];
        [cell.Focuson addTarget:self selector:@selector(Focuson)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if (indexPath.section == 1) {
        TwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"two"];
        if (cell == nil) {
            cell = [[TwoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"two"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.nameleft.text = @"张勇";
        cell.nameright.text = @"夏术阶";
        [cell.left addTarget:self selector:@selector(nemaleft)];
        [cell.right addTarget:self selector:@selector(nemaright)];
        cell.labelright.text = @"肾上腺肿瘤";
        cell.labelleft.text = @"骨盆骨折";
        cell.widthr = [ToolUtil autoWidth:@"肾上腺肿瘤" width:0 height:20 num:12];
        cell.widthl = [ToolUtil autoWidth:@"骨盆骨折" width:0 height:20 num:12];
        return cell;
    }
    else if (indexPath.section == 2) {
        [SingletonStoreSimpleData shareViewController].array = @[[UIImage imageNamed:@"shouye3"],[UIImage imageNamed:@"shouye4"],[UIImage imageNamed:@"shouye5"],[UIImage imageNamed:@"shouye6"],[UIImage imageNamed:@"shouye8"]].mutableCopy;
        ThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"three"];
        if (cell == nil) {
            cell = [[ThreeCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"three"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if (indexPath.section == 3) {
        FourCell *cell = [tableView dequeueReusableCellWithIdentifier:@"four"];
        if (cell == nil) {
            cell = [[FourCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"four"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if (indexPath.section == 4) {
        FiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"five"];
        if (cell == nil) {
            cell = [[FiveCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"five"];
        }
        cell.img.image = [UIImage imageNamed:@"shouye3"];
        cell.title.text = @"上班族如何打好冬季“保胃战”?";
        cell.neirong.text = @"冬季是胃病的高发期，到医院里可以发现，求诊的患者中，年轻的的上班族几乎占了一半";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else{
        return 0;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1 || section == 3 || section == 4) {
        return 35*Height;
    }else{
        return 20;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0 || section == 2 || section == 3) {
        return 20*Height;
    }else{
        return 0.1;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 180*Height;
    }
    else if (indexPath.section == 1) {
        return 90*Height;
    }
    else if (indexPath.section == 2) {
        return 110;
    }
    else if (indexPath.section == 3) {
        return 120*Height;
    }
    else if (indexPath.section == 4) {
        return 100*Height;
    }
    else{
        return 0;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSArray *arr = @[@"",@"专家团队",@"",@"常见疾病",@"热门资讯"];

    if (section == 1) {
        HeadView *head = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        head.backgroundColor = [UIColor whiteColor];
        head.img.image = [UIImage imageNamed:@"duoren.png"];
        head.label.text = arr[section];
        head.beijin.backgroundColor = [UIColor colorWithRed:86.0f/255.0f green:138.0f/225.0f blue:255.0f/255.0f alpha:1];
        [head.right addTarget:self selector:@selector(zhuanjia)];
        
        return head;
    }else if (section == 3)
    {
        HeadView *three = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        three.backgroundColor = [UIColor whiteColor];
        three.img.image = [UIImage imageNamed:@"changjian.png"];
        three.label.text = arr[section];
        three.beijin.backgroundColor = [UIColor colorWithRed:136.0f/255.0f green:193.0f/225.0f blue:38.0f/255.0f alpha:1];
        [three.right addTarget:self selector:@selector(changjian)];
        return three;
    }else if(section == 4)
    {
        HeadView *foun = [[HeadView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 35)];
        foun.backgroundColor = [UIColor whiteColor];
        foun.img.image = [UIImage imageNamed:@"remen.png"];
        foun.label.text = arr[section];
        foun.beijin.backgroundColor = [UIColor colorWithRed:241.0f/255.0f green:82.0f/225.0f blue:44.0f/255.0f alpha:1];
        [foun.right addTarget:self selector:@selector(remen)];
        return foun;
    }else{
        return nil;
    }
    
}
//挂号点击事件
-(void)registered{
    NSLog(@"挂号");
    RegistrationViewController *registration = [RegistrationViewController new];
    [self.navigationController pushViewController:registration animated:YES];
    registration.view.backgroundColor = [UIColor whiteColor];
    registration.navigationController.navigationBar.hidden = NO;
}
//在线咨询
-(void)Theinquiry{
    NSLog(@"在线咨询");
    TheinquiryViewController *theinquiry = [TheinquiryViewController new];
    theinquiry.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:theinquiry animated:YES];
    theinquiry.navigationController.navigationBar.hidden = NO;
}
//微医快约
-(void)Quickabout{
    NSLog(@"微医快约");
    QuickaboutViewController *quickbout = [QuickaboutViewController new];
    [self.navigationController pushViewController:quickbout animated:YES];
    quickbout.navigationController.navigationBar.hidden = NO;
    quickbout.view.backgroundColor = [UIColor whiteColor];
    //quickbout.navigationController.navigationBarHidden = NO;
}
//我的关注
-(void)Focuson{
    NSLog(@"我的关注");
    FocusonViewController *focuson = [FocusonViewController new];
    [self.navigationController pushViewController:focuson animated:YES];
    focuson.view.backgroundColor = [UIColor whiteColor];
    focuson.navigationController.navigationBar.hidden = NO;
}
//专家
-(void)zhuanjia{
    NSLog(@"专家");
    [self.navigationController pushViewController:[[MoreTeamViewController alloc] init] animated:YES];
}
//常见
-(void)changjian{
    ModelCrowdViewController *model = [[ModelCrowdViewController alloc] init];
    [self.navigationController pushViewController:model animated:YES];
    model.navigationController.navigationBar.hidden = NO;
    NSLog(@"常见");
}
//热门
-(void)remen{
    NSLog(@"热门");
    HotViewController *hot = [HotViewController new];
    [self.navigationController pushViewController:hot animated:YES];
    hot.navigationController.navigationBar.hidden = NO;
    
}
//专家团队的点击方法
-(void)nemaleft{
    NSLog(@"left");
    TeamViewController *team = [TeamViewController new];
    [self.navigationController pushViewController:team animated:YES];
    team.navigationController.navigationBar.hidden = NO;
}
//专家个人点击
-(void)nemaright{
    NSLog(@"right");
    TeamViewController *team = [TeamViewController new];
    [self.navigationController pushViewController:team animated:YES];
    team.navigationController.navigationBar.hidden = NO;
}
@end
